<?php

/**
 * @Author: wuchenge
 * @Date:   2022-04-26 15:21:46
 * @Email: ligui0506@126.com
 * @Descript:
 */
namespace App\Requests;

use Illuminate\Http\Request;

class AdminRequest extends FormRequest
{
    /**
     * @param Request $request
     */
    public function rules(Request $request)
    {
        $params = $request->input();
        $id     = 0;
        if (array_key_exists('id', $params)) {
            $id = $params['id'];
        }
        return [
            'username'  => [
                'required',
                'unique:admins,username,' . $id,
            ],
            'pwd'       => [
                'required',
                'min:6',
                'max:20',
            ],
            'nick_name' => [
                'required',
                'min:1',
                'max:10',
            ],

        ];
    }

    public function messages()
    {
        return [
            'username.required'  => '10301',
            'username.unique'    => '帐号已存在',
            'pwd.required'       => '10303',
            'pwd.min'            => '密码不能少于6位',
            'pwd.max'            => '密码不能多于20位',
            'nick_name.required' => '10304',
            'nick_name.min'      => '昵称不能少于6位',
            'nick_name.max'      => '昵称不能多于10位',
        ];
    }

    /**
     * @var array
     */
    public $scene = [
        'admin.admin.create' => ['username', 'pwd', 'nick_name'],
        'admin.admin.update' => ['username', 'nick_name'],
    ];
}
